package academia.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class clienteCRUD {
	public void criar(Connection con, Cliente cliente) throws SQLException{
		String sql = "insert into cliente values (?,?,?,?)";
		try (PreparedStatement stm = con.prepareStatement(sql)){
			stm.setString(1, cliente.nome);
			stm.setDouble(2, cliente.cpf);
			stm.setDouble(3, cliente.rg);
			stm.setString(4, cliente.uf);
			stm.executeUpdate();
			
		}
	}
}
public List<Cliente> ler(Connect con) throws SQLException {
	List<Cliente> lista = new ArrayList<>();
	String sql = "select nome,rg,cpf,uf from cliente";
	try (PreparedStatement stm = con.prepareStatement(sql)ResultSet rs = stm.executeQuery()){
		while(rs.next()) {
			lista.add(new Cliente(rs.getString(1), getDouble(2), getDouble(3), getString(4)));
			
		}
	}
	return lista;
	public static void main(String[] args) throws SQLException{
	String url = "jdbc:oracle:thin:@localhost:1521:xe";
	try (Connection con = DriverManager.getConnection(url, "jefferson", "senha1"));
		ClienteCRUD crud = new ClienteCRUD();
		
		Cliente cliente1 = new Cliente("Ronaldo", 1234567890, 12345678, "PE");
		
			
		crud.criar(con, cliente1);
		
		List<Cliente> clientes = crud.ler(con);
		for (Cliente cliente : clientes){
			System.out.println(cliente);
		}
		
			
	}
		
}
